package com.goods.business.converter;

import com.goods.common.model.business.ProductCategory;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.ProductCategoryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

public class ProductCategoryConverter {

    public static List<ProductCategoryTreeNodeVO> converterToProductCategoryTreeNodeVO(List<ProductCategory> productCategoryList) {
        List<ProductCategoryTreeNodeVO> productCategoryTreeNodeVOS = new ArrayList<>();
        if (!CollectionUtils.isEmpty(productCategoryList)){
            for (ProductCategory productCategory : productCategoryList) {
                ProductCategoryTreeNodeVO productCategoryTreeNodeVO = new ProductCategoryTreeNodeVO();
                BeanUtils.copyProperties(productCategory,productCategoryTreeNodeVO);
                productCategoryTreeNodeVO.setPid(productCategory.getPid());
                productCategoryTreeNodeVO.setId(productCategory.getId());
                productCategoryTreeNodeVOS.add(productCategoryTreeNodeVO);
            }
        }
        return productCategoryTreeNodeVOS;
    }

    public static ProductCategoryVO converterToProductCategoryVO(ProductCategory productCategory) {
        if (productCategory != null){
            ProductCategoryVO productCategoryVO = new ProductCategoryVO();
            BeanUtils.copyProperties(productCategory,productCategoryVO);
            return productCategoryVO;
        }
        return null;
    }
}
